package com;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockTest {
	public static void main(String[] args){  
		ArrayBlockingQueue queue = new ArrayBlockingQueue<String>(1);
        Thread i1 = new Thread(new RunIt3(queue));  
        Thread i2 = new Thread(new RunIt3(queue));  
        i1.start();  
        i2.start();  
        i2.interrupt();  
       
    }  
  
}
  
class RunIt3 implements Runnable{  
  
	private ArrayBlockingQueue queue;
	
	public RunIt3(ArrayBlockingQueue queue){
		this.queue= queue;
	}
	
    private static ReentrantLock lock = new ReentrantLock();  
    public void run(){  
        try{  
//            ---------------------------------a  
//            lock.lock();  
            lock.lockInterruptibly();   
//        	queue.add(Thread.currentThread().getName());
        	
            System.out.println(Thread.currentThread().getName() + " running");  
            TimeUnit.SECONDS.sleep(3);  
            
            System.out.println(Thread.currentThread().getName() + " finished");  
        }  
        catch (InterruptedException e){ 
        	lock.unlock();
        	e.printStackTrace();
            System.out.println(Thread.currentThread().getName() + " interrupted");  
  
        }  
  
    }  
}
